with open('input.txt') as file:
    ids = set()

    for line in file.readlines():
        row = int(line[:7].replace('F', '0').replace('B', '1'), 2)
        col = int(line[7:].replace('L', '0').replace('R', '1'), 2)

        ids.add(row * 8 + col)

    for i in range(1, 0b1_0000000_000):
        if i not in ids and i - 1 in ids and i + 1 in ids:
            print(i)
            break